import QtQuick
import QtQuick.Particles
import QtQuick.Shapes
Rectangle {
    id: root
    width: 360
    height: 540
    color: "black"

    Rectangle {
        id:rtCar
        width: 50
        height: 50
        //anchors.horizontalCenter: parent.horizontalCenter
        Image{
            id:img
            anchors.fill: parent
            source: "qrc:/image/fj2.png"
        }
        color: "black"
    }

    ParticleSystem {
        id: particles
        anchors.fill: parent
        ImageParticle {  // 渲染器，烟雾
            id: smoke
            system: particles
            anchors.fill: parent
            groups: ["A", "B"]
            source: "qrc:///particleresources/glowdot.png"
            colorVariation: 0
            color: "#00111111"
        }

        ImageParticle { // 渲染器，子弹
            id: zd
            anchors.fill: parent
            system: particles
            groups: ["F"]
            source: "qrc:/image/zd1.png"
            colorVariation: 0.1
            //color: "green"
        }

        ImageParticle { // 渲染器，亮度
            id: flame
            anchors.fill: parent
            system: particles
            groups: ["C", "D", "G"]
            source: "qrc:/image/glowdot.png"
            colorVariation: 0.1
            color: "#00ff400f"
        }

        // 底层一排火焰
        Emitter {   // 发射器:发射粒子，包含时间、位置，轨迹，但没有可视化外观，需要至少一个渲染器
            id: fire
            system: particles
            group: "C"  // 逻辑粒子组

            y: parent.height
            width: parent.width

            emitRate: 350
            lifeSpan: 3500

            acceleration: PointDirection { y:-17;
                xVariation:3;
            }

            velocity: PointDirection {xVariation:3}

            size:24

            sizeVariation: 8
            endSize: 4

        }

        // 底层火焰上的一层烟雾，跟随火层 fire
        TrailEmitter {
            id: fireSmoke
            group: "B"
            system: particles
            follow: "C"
            width: root.width
            height: root.height - 68  // 火层上方

            emitRatePerParticle: 1
            lifeSpan: 2000

            emitWidth:10
            emitHeight:10
            velocity: PointDirection {y:-17*6; yVariation: -17; xVariation: 3}
            acceleration: PointDirection {xVariation: 3}

            size: 36
            sizeVariation: 8
            endSize: 16
        }

        Emitter {   // 发射火星
            id: balls
            system: particles
            group: "E"
            enabled: false
            y: parent.height
            width: parent.width

            emitRate: 2
            lifeSpan: 7000

            velocity: PointDirection {y:-17*4*2; xVariation: 6*6}
            acceleration: PointDirection {y: 17*2; xVariation: 6*6}

            size: 8
            sizeVariation: 4
        }

        TrailEmitter {   // 跟踪火星
            id: fireballFlame
            anchors.fill: parent
            system: particles
            group: "D"
            follow: "E"

            emitRatePerParticle: 120
            lifeSpan: 180
            emitWidth: TrailEmitter.ParticleSize
            emitHeight: TrailEmitter.ParticleSize
            emitShape: EllipseShape{}

            size: 16
            sizeVariation: 4
            endSize: 4
        }

        TrailEmitter {
            id: fireballSmoke
            anchors.fill: parent
            system: particles
            group: "A"
            follow: "E"

            emitRatePerParticle: 128
            lifeSpan: 2400
            emitWidth: TrailEmitter.ParticleSize
            emitHeight: TrailEmitter.ParticleSize
            emitShape: EllipseShape{}

            velocity: PointDirection {yVariation: 16; xVariation: 16}
            acceleration: PointDirection {y: -16}

            size: 24
            sizeVariation: 8
            endSize: 8
        }
        Turbulence { //A bit of turbulence makes the smoke look better
            anchors.fill: parent
            groups: ["A","B"]
            strength: 100
            system: particles
        }

        Emitter {   // 发射子弹
            id: zdEmit
            system: particles
            group: "F"
            enabled: false
            y: rtCar.y + 50 + 2
            x: rtCar.x + 25 - 2
            width: 1

            emitRate: 20
            lifeSpan: 3000

            velocity: PointDirection {y:100;}
            acceleration: PointDirection {y: 100;}

            size: 10
            sizeVariation: 0
        }

        TrailEmitter {   // 跟踪子弹
            id: zdFlame
            anchors.fill: parent
            system: particles
            group: "G"
            follow: "F"

            emitRatePerParticle: 100
            lifeSpan: 180
            emitWidth: 10 // TrailEmitter.ParticleSize
            emitHeight: 10 //TrailEmitter.ParticleSize
            emitShape: EllipseShape{}

            size: 16
            sizeVariation: 4
            endSize: 4

        }





    }

    MouseArea {
        id:mouse
        anchors.fill: parent
        hoverEnabled: true
        onPositionChanged: {
            if (mouse.pressed) {
                //console.log("x = " + mouse.mouseX)
                rtCar.x = mouse.mouseX - 25
                rtCar.y = mouse.mouseY - 25
                zdEmit.enabled = true
            }
        }


        // onEntered: {

        // }
        onReleased: {
            zdEmit.enabled = false
        }
    }
}
